package sdk.webview.fmc.com.fmcsdk.view;

import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import sdk.webview.fmc.com.fmcsdk.R;


/**
 * 自定的dialog提示框，包括GPS开关，清理缓存，更新APK
 */
public class ErrorDialog extends Dialog {
	private Context context;
	/**标题和内容*/
	private String msg,tips;

	private TextView confirm;
	private TextView tv_message;

	//只有提示内容的消息框
	public ErrorDialog(Context context,String tips, String msg) {
		super(context, R.style.Dialog);
		this.context = context;
		this.msg = msg;
		this.tips = tips;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.error_dialog);
		confirm = (TextView) findViewById(R.id.confirm);
		TextView cancel = (TextView) findViewById(R.id.cancel);
		tv_message = (TextView) findViewById(R.id.tv_message);
		tv_message.setText(tips);
		TextView look_detail = (TextView)findViewById(R.id.look_detail);
		confirm.setOnClickListener(new clickListener());
		cancel.setOnClickListener(new clickListener());
		look_detail.setOnClickListener(new clickListener());
		//试着提示框的位置和大小
		Window dialogWindow = getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高
		lp.width = (int) (d.widthPixels * 0.9);
		dialogWindow.setAttributes(lp);

	}

	public void setConfirmText(String text){
		confirm.setText(text);
	}


	private class clickListener implements View.OnClickListener {
		@Override
		public void onClick(View v) {
			int id = v.getId();
			if (id==R.id.confirm){
				dismiss();
			}else if (id==R.id.cancel){
				dismiss();
			}else if (id==R.id.look_detail){
				tv_message.setText(msg);
			}

		}

	}


}
